function wuyuan(R0, x, w) {
    let n = R0.length;
    let mm = R0[0].length;
    let m = mm / 2;
    let a = [], b = [];
    for (let i = 0; i < n; i++) {
        a[i] = []
        b[i] = [];
        for (let j = 0; j < m; j++) {
            a[i][j] = R0[i][j * 2];
            b[i][j] = R0[i][j * 2 + 1];
        }
    }
    let ap = [], bp = [];
    for (let i = 0; i < n; i++) {
        ap[i] = R0[i][0];
        bp[i] = R0[i][mm - 1];
    }
    let fah = x.length;// 学生个数
    let fal = x[0].length;// 指标个数
    let k = [];
    for (let i = 0; i < n; i++) {
        k[i] = [];
        for (let j = 0; j < m; j++) {
            k[i][j] = 0;
        }
    }
    let index = [];
    let jstar = 0;
    for (let s = 0; s < fah; s++) { // 循环每个学生
        for (let g = 0; g < fal; g++) { // 循环每个指标
            for (let i = 0; i < n; i++) {
                for (let j = 0; j < m; j++) {
                    if (a[i][j] == b[i][j]) {
                        if (x[s][g][i] == a[i][j]) { // 修改此处
                            k[i][j] = 0;
                        } else {
                            let pp = Math.abs(x[s][g][i] - 0.5 * (ap[i] + bp[i])) - 0.5 * (bp[i] - ap[i]);
                            k[i][j] = Math.abs(x[s][g][i] - a[i][j]) / (pp - Math.abs(x[s][g][i] - a[i][j]));
                        }
                    } else {
                        if (x[s][g][i] >= a[i][j] && x[s][g][i] <= b[i][j]) { // 修改此处
                            let p = Math.abs(x[s][g][i] - 0.5 * (a[i][j] + b[i][j])) - 0.5 * (b[i][j] - a[i][j]);
                            k[i][j] = -p / Math.abs(b[i][j] - a[i][j]);
                        } else {
                            let p = Math.abs(x[s][g][i] - 0.5 * (a[i][j] + b[i][j])) - 0.5 * (b[i][j] - a[i][j]);
                            let pp = Math.abs(x[s][g][i] - 0.5 * (ap[i] + bp[i])) - 0.5 * (bp[i] - ap[i]);
                            k[i][j] = p / (pp - p);
                        }
                    }
                }
            }
            let kp = [];
            for (let j = 0; j < m; j++) {
                let sum = 0;
                for (let i = 0; i < w.length; i++) {
                    sum += w[i] * k[i][j];
                }
                kp[j] = sum;
            }
            let kpmaxIndex = 0;
            let kpmax = kp[0];
            let kpmin = kp[0];
            for (let i = 1; i < kp.length; i++) {
                if (kp[i] > kpmax) {
                    kpmax = kp[i];
                    kpmaxIndex = i;
                }
                if (kp[i] < kpmin) {
                    kpmin = kp[i];
                }
            }
            index.push(kpmaxIndex);
            let avkpp = [];
            let avkppSum = 0;
            for (let i = 0; i < m; i++) {
                avkpp[i] = (kp[i] - kpmin) / (kpmax - kpmin);
                avkppSum += avkpp[i];
            }
            let jup = 0;
            for (let i = 0; i < m; i++) {
                jup += i * avkpp[i];
            }
            jstar += jup / avkppSum; // 修改此处
        }
    }
    jstar /= (fah * fal); // 修改此处
    // 根据评价结果，判断属于哪一级别
    if (jstar >= 0 && jstar <= 1) {
        return "差";
    } else if (jstar > 1 && jstar <= 2) {
        return "中";
    } else if (jstar > 2 && jstar <= 3) {
        return "良";
    } else if (jstar > 3 && jstar <= 4) {
        return "优";
    }
}


const R0 = [
    [0, 10, 11, 20, 21, 30, 31, 40],
    [0, 10, 11, 20, 21, 30, 31, 40],
    [0, 10, 11, 20, 21, 30, 31, 40],
    [0, 10, 11, 20, 21, 30, 31, 40],
];

const x = [
    [21, 27, 33, 24],

];

const w = [0.25, 0.25, 0.25, 0.25];
console.log(wuyuan(R0, x, w), '结果')
